package com.service.atm;

import com.bpms.common.CommonUtil;
import com.bpms.common.VO;
import com.bpms.eai.PackTool;
import com.bpms.esb.IService;

public class Parse_atm_check_image extends PackTool implements IService {
	/**
	 * 接收支票影像实现类
	 */
	@Override
	public VO exec(VO args) {
		byte[] body = (byte[]) args.getObj("body");
		VO r = new VO();
		try {
//			r.setAttr("data", args.getAttr("data"));
			r.voType = "ATM.Answer_atm_check_image";
			String DEVICENO = this.getField(body, body.length, "1001"); // 设备号  1001
			String NETNUM = this.getField(body, body.length, "1002"); // 网点号  1002
			String CERTNUM = this.getField(body, body.length, "1003"); // 认证码  1003
			String DATETIME = this.getField(body, body.length, "1004"); // 日期时间  1004
			String BILLTYPE = this.getField(body, body.length, "1005"); // 业务类型  1005 01现金支票、02转账支票、04贷记凭证、05电汇凭证
			String LAUNCHSITE = this.getField(body, body.length, "1006"); // 发起网点号 1006
			String PAYEEBANK = this.getField(body, body.length, "1007"); // 收款人开户行 1007
			String DRAWEEBANK = this.getField(body, body.length, "1008"); // 付款人开户行 1008
			String PAYINGMARK = this.getField(body, body.length, "1009"); // 收付款标志  1009
			String BEARERTYPE = this.getField(body, body.length, "1010"); // 持票人类型 1010
			String IDCARD = this.getField(body, body.length, "1011"); // 身份证号码 1011
			String IDNAME = this.getField(body, body.length, "1012"); // 身份证姓名 1012
			String ISPASSWORD = this.getField(body, body.length, "1013"); // 是否支付密码  1013
			String SYSTEMTYPE = this.getField(body, body.length, "1014"); // 对应集中处理系统业务类型  1014 B02本行支票收款、B01本行支票付款、B03跨行支付密码支票收款（交换提出借方）、B04跨行非支付密码支票收款（交换提出借方）、B05踌行支票付款（交换提出贷方）
			String PHONENUMBER = this.getField(body, body.length, "1015"); // 联系电话
			String ISSUEDATE = this.getField(body, body.length, "1016"); 	// 凭证日期
			String AMOUNT = this.getField(body, body.length, "1017");	// 金额
			String BILLNO =  this.getField(body, body.length, "1018");	// 凭证编号
//			String BILLNO =  "";	// 凭证编号
			String IMGDATA = this.getField(body, body.length, "1019"); // 图码数据
			String IMGNUM = this.getField(body, body.length, "1020"); // 影像张数
			String IMGORDER = this.getField(body, body.length, "1021"); // 影像顺序号（当前上传的为第几张影像）
			String DIWENCHECK = this.getField(body, body.length, "1022"); // 票据底纹是否通过
			// 获取影像字符串
			int imgnum = Integer.parseInt(IMGNUM);
			if (imgnum > 0)
				for (int i = 1; i < (imgnum + 1); i++) {
					if (i < 10)
						r.setAttr("photo" + i,
								getField(body, body.length, "T00" + i));
					if (i >= 10 && i < 100)
						r.setAttr("photo" + i,
								getField(body, body.length, "T0" + i));
					if (i >= 100)
						r.setAttr("photo" + i, getField(body, body.length, "T" + i));
				}

			r.setAttr("DEVICENO", DEVICENO);
			r.setAttr("NETNUM", NETNUM);
			r.setAttr("CERTNUM", CERTNUM);
			r.setAttr("DATETIME", DATETIME);
			r.setAttr("BILLTYPE", BILLTYPE);
			r.setAttr("LAUNCHSITE", LAUNCHSITE);
			r.setAttr("PAYEEBANK", PAYEEBANK);
			r.setAttr("DRAWEEBANK", DRAWEEBANK);
			r.setAttr("PAYINGMARK", PAYINGMARK);
			r.setAttr("BEARERTYPE", BEARERTYPE);
			r.setAttr("IDCARD", IDCARD);
			r.setAttr("IDNAME", IDNAME);
			r.setAttr("ISPASSWORD", ISPASSWORD);
			r.setAttr("SYSTEMTYPE", SYSTEMTYPE);
			r.setAttr("PHONENUMBER", PHONENUMBER);
			r.setAttr("ISSUEDATE", ISSUEDATE);
			r.setAttr("AMOUNT", AMOUNT);
			r.setAttr("BILLNO", BILLNO);
			r.setAttr("IMGDATA", IMGDATA);
			r.setAttr("IMGNUM", IMGNUM);
			r.setAttr("IMGORDER", IMGORDER);
			r.setAttr("DIWENCHECK", DIWENCHECK);

			CommonUtil.debug("ATM.Parse_atm_check_image parseBuffer");
			return r;
		} catch (Exception e) {
			CommonUtil.debug("ATM.Parse_atm_check_image exception", e);
			return null;
		}
	}

}
